/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Create: 2024-11-19
 */

#ifndef RA_RESOURCE_MANAGER_H
#define RA_RESOURCE_MANAGER_H
#include <mutex>
#include "dtype_common.h"
#include "hccl_common.h"
#include "adapter_hccp.h"
#include "interface_hccl.h"

namespace hccl {
constexpr u32 TIME_FROM_1900 = 1900;
class RdmaResourceManager {
public:
    static RdmaResourceManager& GetInstance();
    HcclResult Init();
    HcclResult DeInit();
    HcclResult GetRdmaHandle(RdmaHandle& rdmaHandle);
    HcclResult GetCqeErrInfo(struct cqe_err_info *infoList, u32 *num);
    HcclResult GetCqeErrInfoByQpn(u32 qpn, struct HcclErrCqeInfo *errCqeList, u32 *num);
private:
    RdmaResourceManager();
    ~RdmaResourceManager();
    RdmaResourceManager(RdmaResourceManager const&) = delete;
    RdmaResourceManager(RdmaResourceManager&&) = delete;
    RdmaResourceManager& operator=(RdmaResourceManager const&) = delete;
    RdmaResourceManager& operator=(RdmaResourceManager &&) = delete;
private:
    s32 deviceLogicId_{};
    u32 devicePhyId_{};
    NICDeployment nicDeploy_ = NICDeployment::NIC_DEPLOYMENT_DEVICE;
    HcclIpAddress ipAddr_{};
    u32 port_{MAX_VALUE_U32};
    RdmaHandle rdmaHandle_{};
    std::mutex cqeErrMapMutex_;
    std::map<u32, std::queue<struct cqe_err_info>> cqeErrPerQP_{}; //key:qp, value:cqe_err_info queue
};

}  // namespace hccl

#endif